/**
**纸张其他入库：选择单据按钮事件
**/
function chooseCLRK(){
	//获取入库类别
	var DJ_TYPE=$('#zza_addWinForm').find('select[qucln=RK_TYPE]').val();
	//获取库房
	var STOCK_ID=$('#zza_addWinForm').find('input[qucln=STOCK_ID]').val();
	//获取纸张类型
	var HT_DJ_TYPE=$('#zza_addWinForm').find('select[qucln=HT_DJ_TYPE]').val();
	
	//入库类型和库房不能为空
	if (DJ_TYPE=='') {
		$.messager.alert('提示','请选择入库类别！');
		return;
	}
	
	if (STOCK_ID==''){
		$.messager.alert('提示','请选择单据库房！');
		return;
	}
	
	if (HT_DJ_TYPE==''){
		$.messager.alert('提示','请选择纸张类型！');
		return;
	}
	
	var dgUrl=_m_url+'fxa/findOtherCk';
	var queryParams={'dsId':'ds_bs_material5','DJ_TYPE':DJ_TYPE,'STOCK_ID':STOCK_ID};
	
	$.ajax({
		type:'post',
		url:_m_url+'fxa/findOtherCk',
		data:{'dsId':'ds_bs_material5','DJ_TYPE':DJ_TYPE,'STOCK_ID':STOCK_ID},
		success:function(data){
			//根据现成的数据展现窗口
			$.ajax({
				type:'post',
				url:_m_url+'fxa/UpdateDefaultOtherck',
				data:{'dsId':'ds_bs_material5','STOCK_ID':STOCK_ID},
				success:function(data){
				} 
			});
			_data_qtcrk('zzaa','ds_bs_material5','clrk_sure1','77','',data,dgUrl,queryParams);
		}
	});
}


/**
**纸张其他入库：选择单据按钮弹框事件
**/
function _data_qtcrk(prefix,dsId,butnId,type,ainitFunc,dataList,dgUrl,queryParams){
	var width = document.documentElement.clientWidth*0.97;
	var height = window.parent.innerHeight-270;
	if($('#'+prefix+'_DATA_WIN').length>0){
		$('#'+prefix+'_DATA_PARENT_PANEL').window('close');
		var obj = document.getElementById(prefix+"_DATA_WIN");
		$('#'+prefix+'_DATA_PARENT_PANEL').remove();
		document.body.removeChild(obj);
	}
	var div_box = document.createElement("DIV");
	div_box.id = prefix+"_DATA_WIN";
	div_box.height = 100;
	document.body.appendChild(div_box);
	$('#'+prefix+'_DATA_WIN').load(_m_url+'singlePages/genFun',
			{'dsId':dsId,'butnId':butnId,'type':type,'staticWebUrl':'','initFunc':'','jspWebUrl':'/model/otherGen/odatalistD'},
			function(){
				$.parser.parse('#'+prefix+'_DATA_DG_PANEL');
				$('#'+prefix+'_DATA_PARENT_PANEL').window({  
					width:document.documentElement.clientWidth,  
					height:document.documentElement.clientHeight,  
					draggable:false,
					top:'0',
					left:'0',
					modal:true,
					resizable:false,
					closable:false,
					collapsible:false,
					maximizable:false,
					minimizable:false
				});  
				$('#'+prefix+'_DATA_PARENT_PANEL').window('open');
				// 加载字段 变不可写 填充数据
				var divName = 'DATA_DATALIST';
				// 加载字段
				$.ajax({
					type:'post',
					url:_m_url+'framework/loadColumnsU',
					data:{'colId':dsId,'type':type},
					success:function(data){
						if(data==""){
							$.messager.alert('提示',"您长时间未操作，系统已经自动退出!，请重新登陆");
						}else{
							var options = jointDGColumn(data[0]);
							var fzClns = options.frozenColumns;
							options.frozenColumns = [[{field:'kk',checkbox:true}]];
							for(var i = 0; i < fzClns[0].length; i ++){
								options.frozenColumns[0].push(fzClns[0][i]);
							}
							//获取div的宽度和高度
							$('#'+prefix+'_DATA_DATALIST').datagrid({
								iconCls:'icon-save',
								pageNumber:1,
								url:dgUrl,
								queryParams:queryParams,
								height:height,
								width:width,
								striped: true,		
								collapsible:true,
								autoRowHeight: false,		
								sortOrder: 'desc',
								remoteSort: false,
								pageList:[300,500,1000],
								columns:options.columns,
								frozenColumns:options.frozenColumns,
								pagination:true,
								rownumbers:true,
								singleSelect:false,
								rowStyler:function(index,row){  
									return window.parent.getRowStyler(index,row,data[0]);
								},
								onRowContextMenu:function(e, rowIndex, rowData){// 右键菜单
								    $('#mm').menu('show', {
								        left:e.pageX,
								        top:e.pageY
								    });
								},
								onClickRow:function(rowIndex,rowData){
									//获取到currentIndex
									var currentIndex=$(this).attr("currentIndex");
									if(rowIndex!=currentIndex){
										var colnName=$(this).attr("colnName");
										$(this).datagrid("endEdit",currentIndex)
										$(this).datagrid("beginEdit",rowIndex);
										$(this).attr("currentIndex",rowIndex);
										var cRowStyle=$($($(this).datagrid("getEditor",{index:rowIndex,field:colnName}).target[0]).parent("td").parents("tr[datagrid-row-index]")[0]).attr("class");
										var amountObj=$($(this).datagrid("getEditor",{index:rowIndex,field:colnName}).target[0]).parent("td").find("#editablebox");
										//清空数量的值
										$($(this).datagrid("getEditor",{index:rowIndex,field:colnName}).target[0]).parent("td").find("input").val("");
										amountObj.focus();
										$($(this).datagrid("getEditor",{index:rowIndex,field:colnName}).target[0]).parent("td").find("#editablebox").css("background-color","#C9ECFE");
									}
								},
								onLoadSuccess:function(data){
									var colnName="H_AMOUNT";
									{if(dsId=='ds_bs_product2'||dsId=='ds_bs_product4'){
										colnName="AMOUNT";
									}
									if(data.rows.length>0)
										$(this).datagrid('beginEdit', 0);
										var ed =$(this).datagrid('getEditor', {index:0,field:colnName});
										if(ed!=null&&ed!=undefined){
											$(this).attr("colnName",colnName);
											$(this).attr("currentIndex",0);
											var amountObj=$($(this).datagrid("getEditor",{index:0,field:colnName}).target[0]).parent("td").find("#editablebox");
											$(amountObj).keydown(function() {
												$('#'+prefix+'_DATA_DATALIST').datagrid('selectRow',0);
											});
											$(amountObj).focus();
											$(amountObj).css("background-color","#C9ECFE");
										}else{
											console.log("===========如果该列表界面没有光标定位，那么请找到对应的数量列，并告诉开发配置");
										}
									}
//									$('#zzaa_commDataLeftD').find('input[qucln=CLSTOCK]').next().attr('disabled',"true");
								},
							});
							$('#'+prefix+'_DATA_DATALIST').datagrid("keyCtr_cp");       // 绑定datagrid 的键盘事件
							if(ainitFunc!='')eval(ainitFunc).call(this,prefix);
						}
					}
				});
			}
		);
}


/**
 * 弹窗的确定按钮
 * @return
 */
function _clrk_sure1(){
	//关闭弹窗
	$('#zzaa_DATA_PARENT_PANEL').window('close');
	//原有明细数据
	var oldRows = $('#zza_addItemDatagrid').datagrid('getRows');
	//获取选择的数据
	var selRows = $('#zzaa_DATA_DATALIST').datagrid('getSelections');
	
	//关闭弹出窗口的editor 
	for(var i=0;i<selRows.length;i++){
		var index=$('#zzaa_DATA_DATALIST').datagrid("getRowIndex",selRows[i]);
		$('#zzaa_DATA_DATALIST').datagrid('endEdit',index);
	}
	var amount;
	var price;
	for ( var j = 0; j < selRows.length; j++) {
		if (selRows[j].CL_UNIT == 'cljlUnit.003') { // 张
			amount = selRows[j].ZHANG_AMOUNT;
			price=selRows[j].CLPRICE_Z;
		} else if (selRows[j].CL_UNIT == 'cljlUnit.002') { // 令
			amount = selRows[j].L_AMOUNT;
			price=selRows[j].CLPRICE_L;
		}
		$('#zza_addItemDatagrid').datagrid('appendRow', {
			
			MAN_BUSINESS:selRows[j].VENDOR_ID,
			CL_ID:selRows[j].CL_ID,
			CL_WEIGHT:selRows[j].CL_WEIGHT,
			CL_GLEN:selRows[j].CL_GLEN,
			CL_GWID:selRows[j].CL_GWID,
			CL_UNIT:selRows[j].CL_UNIT,
			PRICE:price,
			AMOUNT:'1',
			REAL_MONEY:selRows[j].AMOUNT==""||selRows[j].AMOUNT==null||selRows[j].AMOUNT==undefined?0:(price*selRows[j].AMOUNT),
			TAX_RATE:'17%',
			REAL_BMONEY:selRows[j].AMOUNT==""||selRows[j].AMOUNT==null||selRows[j].AMOUNT==undefined?0:(price*selRows[j].AMOUNT)/1.17,
			XT_ID:selRows[j].XT_ID,
			YINCI:selRows[j].BANYINCI==""||selRows[j].BANYINCI==null||selRows[j].BANYINCI==undefined?0:selRows[j].BANYINCI
			
		});
	}
}

/**
 * 纸张其他入库的删除明细的按钮
 */
function deleteCLRK(obj,dgUrl,queryParams){
	//获取选中的行
	var oldRows = $('#zza_addItemDatagrid').datagrid('getSelections');
	for(var i=0;i<oldRows.length;i++){
		var rowIndex= $('#zza_addItemDatagrid').datagrid('getRowIndex',oldRows[i]);
		$('#zza_addItemDatagrid').datagrid('deleteRow',rowIndex);
	}
}